#! /usr/bin/make -f

PACKAGE := dput
TMPDIR := debian/tmp

app_library_path := usr/share/${PACKAGE}
bin_path := usr/bin
manpage_path := usr/share/man
bash_completion_path := etc/bash_completion.d
package_doc_path := usr/share/doc/${PACKAGE}

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	test -e debian/control
	touch build-stamp

clean:
	test -e debian/control
	test 0 = "`id -u`" || (echo need root privileges; exit 1)
	rm -f build-stamp install-stamp
	rm -rf debian/substvars debian/files $(TMPDIR)
	rm -rf *.pyc *~ debian/*~

# Build architecture-independent files here.
binary-indep: build debian/control
	test -e debian/control
	test 0 = "`id -u`" || (echo need root privileges; exit 1)
	rm -rf debian/substvars $(TMPDIR)
	install -d --mode=0755 $(TMPDIR)
	install -d --mode=0755 $(TMPDIR)/DEBIAN
	install -d --mode=0755 $(TMPDIR)/${bin_path}
	install -d --mode=0755 $(TMPDIR)/etc
	install -d --mode=0755 $(TMPDIR)/${bash_completion_path}
	install -d --mode=0755 $(TMPDIR)/${package_doc_path}
	install -d --mode=0755 $(TMPDIR)/${manpage_path}/man1
	install -d --mode=0755 $(TMPDIR)/${manpage_path}/man5
	install -d --mode=0755 $(TMPDIR)/${app_library_path}
	install -d --mode=0755 $(TMPDIR)/${app_library_path}/methods
	install -d --mode=0755 $(TMPDIR)/${app_library_path}/helper
	install --mode=0644 dput/__init__.py $(TMPDIR)/${app_library_path}
	install --mode=0644 dput/methods/*.py $(TMPDIR)/${app_library_path}/methods
	install --mode=0644 dput/helper/*.py $(TMPDIR)/${app_library_path}/helper
	install --mode=0755 dput/helper/security-warning $(TMPDIR)/${app_library_path}/helper
	install --mode=0755 dput/dput.py $(TMPDIR)/${app_library_path}
	ln --symbolic ../../${app_library_path}/dput.py $(TMPDIR)/${bin_path}/dput
	install --mode=0755 dput/dcut.py $(TMPDIR)/${app_library_path}
	ln --symbolic ../../${app_library_path}/dcut.py $(TMPDIR)/${bin_path}/dcut
	install --mode=0644 dput.cf $(TMPDIR)/etc
	install --mode=0644 dput.1 $(TMPDIR)/${manpage_path}/man1
	install --mode=0644 dcut.1 $(TMPDIR)/${manpage_path}/man1
	install --mode=0644 dput.cf.5 $(TMPDIR)/${manpage_path}/man5
	install --mode=0644 README $(TMPDIR)/${package_doc_path}
	install --mode=0644 FAQ $(TMPDIR)/${package_doc_path}
	install --mode=0644 copyright $(TMPDIR)/${package_doc_path}
	install --mode=0644 TODO $(TMPDIR)/${package_doc_path}
	install --mode=0644 THANKS $(TMPDIR)/${package_doc_path}
	install --mode=0644 debian/changelog $(TMPDIR)/${package_doc_path}
	install --mode=0644 bash_completion $(TMPDIR)/${bash_completion_path}/${PACKAGE}
	gzip -9 $(TMPDIR)/${manpage_path}/man1/*
	gzip -9 $(TMPDIR)/${manpage_path}/man5/*
	gzip -9 $(TMPDIR)/${package_doc_path}/changelog
	cd $(TMPDIR); find -type f \! -regex '.*/DEBIAN/.*' -printf '%P\0' | xargs -r0 md5sum > DEBIAN/md5sums
	install --mode=0644 debian/conffiles $(TMPDIR)/DEBIAN
	install --mode=0755 debian/prerm $(TMPDIR)/DEBIAN
	install --mode=0755 debian/postinst $(TMPDIR)/DEBIAN
	dpkg-gencontrol -isp
	dpkg --build $(TMPDIR) ..

# Build architecture-dependent files here.
binary-arch: build

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary


# Local variables:
# coding: utf-8
# mode: make
# End:
# vim: fileencoding=utf-8 filetype=make :
